// pages/healthy_analysis/healthy_analysis.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    analysisArr: [
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var hzid = options.hzid
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.setData({
      hzid: hzid,
      backgroundColor: bgc
    })
  },
  //分析结果
  analysisResult: function (e) {
    var that = this
    var length = that.data.analysisArr.length
    var index = e.currentTarget.dataset.index
    var contrastArr = that.data.contrastArr
    console.log(contrastArr, index)
    var str = JSON.stringify(contrastArr)
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/analysis_result/analysis_result?length=' + length + "&index=" + index+"&str="+str,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getFenxi()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getFenxi: function () {
    var that = this
    var hzid = that.data.hzid
    app.util.request({
      'url': 'entry/wxapp/Fenxi',
      data: {
        useropenid: wx.getStorageSync('openid'),
        hzid: hzid
      },
      success: function (res) {
        console.log(res)
        var reportObj = res.data.data
        var analysisArr = that.data.analysisArr
        for (var i = 0, len = reportObj.length;i <len;i++){
          analysisArr[i] = {}
          analysisArr[i].img = "../images/newimg/icon_21.png",
          // analysisArr[i].tips = "检测" + reportObj[i][0].title+"功能的重要指标"
            analysisArr[i].title = reportObj[i][0].title
        }
        that.setData({
          contrastArr: reportObj,
          analysisArr: analysisArr
        })
      }
    })
  }
})